import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:ytbusiness/models/insurance_model.dart';
import 'package:ytbusiness/repository/scout_request.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/widgets.dart';

//保司信息
class InsuranceCompanyInfo extends StatefulWidget {
  @override
  _InsuranceCompanyInfoState createState() => _InsuranceCompanyInfoState();
}

class _InsuranceCompanyInfoState extends State<InsuranceCompanyInfo> {
  InsuranceData _insuranceData;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _getInsuranceInfo();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: customAppBar(context, title: ""),
      body: ListView(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Column(
                children: [
                  Container(
                    margin: EdgeInsets.only(
                        top: setWidth(25), bottom: setWidth(16)),
                    height: setWidth(42),
                    width: setWidth(76),
                    color: Color(0xff989898),
                  ),
                  Container(
                    child: Text(
                      _insuranceData?.name ?? "",
                      style: TextStyle(
                          color: Color(0xff323232),
                          fontSize: setSp(15),
                          fontWeight: FontWeight.w500),
                    ),
                  ),
                  SizedBox(
                    height: setWidth(7),
                  ),
                  Container(
                    child: Text(
                      "简称:${_insuranceData?.nameShorter ?? ""}",
                      style: TextStyle(
                          color: Color(0xff989898), fontSize: setSp(12)),
                    ),
                  )
                ],
              ),
            ],
          ),
          SizedBox(
            height: setWidth(40),
          ),
          _item(title: "上级单位", content: "${_insuranceData?.name ?? ""}"),
          _item(title: "所在地区", content: "${_insuranceData?.name ?? ""}"),
          _item(title: "分支公司(营业部)名称", content: "中心支公司"),
          _item(title: "负责人", content: _insuranceData?.name ?? ""),
          _item(title: "联系电话", content: "${_insuranceData?.hojiTel ?? ""}"),
          _item(title: "座机", content: "${_insuranceData?.landLine ?? ""}"),
          _item(title: "客服", content: "${_insuranceData?.serviceTel ?? ""}"),
        ],
      ),
    );
  }

  Container _item({String title, String content}) {
    return Container(
      child: Column(
        children: [
          Container(
            margin: EdgeInsets.only(
                top: setWidth(22),
                bottom: setWidth(22),
                left: setWidth(15),
                right: setWidth(15)),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Container(
                  child: Text(
                    title,
                    style: TextStyle(
                        color: Color(0xff323232), fontSize: setSp(15)),
                  ),
                ),
                Expanded(
                  child: Container(
                    alignment: Alignment.centerRight,
                    child: Text(
                      content,
                      style: TextStyle(
                          color: Color(0xff989898), fontSize: setSp(15)),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ),
                  ),
                ),
              ],
            ),
          ),
          Container(
            height: setWidth(0.5),
            color: Color(0xffF0F0F0),
          )
        ],
      ),
    );
  }

  //获取保司信息
  _getInsuranceInfo() {
    ScoutRequest.insuranceInfo(context: context).then((value) {
      setState(() {
        _insuranceData = value?.insuranceData;
      });
    });
  }
}
